package com.leo.m1803.d11;

/**
 * Created by LEO on 2018/3/11.
 */
public class Offer03 {
    public static boolean find(int[][] a, int target){
        if (a == null || a.length==0 || a[0].length==0){ return false; }
        int rows = a.length;
        int cols = a[0].length;
        int i = 0, j = cols-1;
        boolean isFind = false;
        while (i< rows && j>=0){
            if (a[i][j] == target){
                isFind = true;
                break;
            }else if (a[i][j] > target){
                j--;
            }else {
                i++;
            }
        }
        return isFind;
    }

    public static void main(String[] args) {
        int[][] a= {{1,2,8,9},
                {2,4,9,12},
                {4,7,10,13},
                {6,8,11,15}};
        System.out.println(find(a, 9));
        System.out.println(find(a, 7));
        System.out.println(find(a, 3));
        System.out.println(find(a, 14));
    }
}
